﻿// CBaseSpell.cs
// Author: Gant Briseno
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
#endregion

namespace SpellEditor
{
    public enum SpellType { Green, Blue, Red, Max };
    public enum SpellProperty { Heatable, Chillable, Conductable, Soakable, Max };
    public enum SpellEffect { None, Frozen, Burned, Brittle, Stunned, Poisoned, Max };
    public enum SpellMoveType { CasterToTarget, OnTarget, Max };

    public class CSpell
    {
        // Color type
        protected SpellType m_Type;

        // Property of the spell
        protected SpellProperty m_Property;

        // The effect the spell causes
        protected SpellEffect m_Effect;

        protected SpellMoveType m_MoveType;

        // Has the player unlocked this spell?
        protected bool m_bUnlocked;

        // Variables
        protected string m_Name;
        protected string m_ImageFilePath;
        protected int m_nPower;
        protected int m_nPowerModifier;
        protected int m_nSpeed;
        protected int m_nSpeedModifier;
        protected int m_nRange;
        protected int m_nRangeModifier;
        protected int m_nRecovery;
        protected int m_nRecoveryModifier;
        protected int m_nTargetArea;
        protected int m_nTargetAreaModifier;
        protected int m_nEffectLength;
        protected int m_nEffectLengthModifier;
        protected int m_nCooldown;
        protected int m_nCooldownModifier;

        public CSpell() { }
        public CSpell(SpellType _type, SpellProperty _prop, SpellEffect _effect, string _name, string _filepath,
            bool _unlocked, int _power, int _speed, int _range, int _recovery, int _targetArea, int _effectLength, 
            int _cooldown, SpellMoveType _move)
        {
            m_Type = _type;
            m_Property = _prop;
            m_Effect = _effect;
            m_Name = _name;
            m_ImageFilePath = _filepath;
            m_nPower = _power;
            m_nSpeed = _speed;
            m_nRange = _range;
            m_nRecovery = _recovery;
            m_nTargetArea = _targetArea;
            m_nEffectLength = _effectLength;
            m_nCooldown = _cooldown;
            m_bUnlocked = _unlocked;
            m_MoveType = _move;

            m_nPowerModifier = 0;
            m_nSpeedModifier = 0;
            m_nRangeModifier = 0;
            m_nRecoveryModifier = 0;
            m_nTargetAreaModifier = 0;
            m_nEffectLengthModifier = 0;
            m_nCooldownModifier = 0;
        }

        public override string ToString()
        {
            return "Name: " + m_Name + " Type: " + m_Type.ToString();
        }

        // Accessors
        public SpellType GetSpellType() { return m_Type; }
        public SpellProperty GetProperty() { return m_Property; }
        public SpellEffect GetEffect() { return m_Effect; }
        public SpellMoveType GetMoveType() { return m_MoveType; }
        public string GetName() { return m_Name; }
        public string GetFilePath() { return m_ImageFilePath; }

        // Modified Accessors
        public int GetPower() { return m_nPower + m_nPowerModifier; }
        public int GetSpeed() { return m_nSpeed + m_nSpeedModifier; }
        public int GetRange() { return m_nRange + m_nRangeModifier; }
        public int GetRecovery() { return m_nRecovery + m_nRecoveryModifier; }
        public int GetTargetArea() { return m_nTargetArea + m_nTargetAreaModifier; }
        public int GetEffectLength() { return m_nEffectLength + m_nEffectLengthModifier; }
        public int GetCooldown() { return m_nCooldown + m_nCooldownModifier; }

        // Unmodified accessors
        public int GetPowerUnmodified() { return m_nPower; }
        public int GetSpeedUnmodified() { return m_nSpeed; }
        public int GetRangeUnmodified() { return m_nRange; }
        public int GetRecoveryUnmodified() { return m_nRecovery; }
        public int GetTargetAreaUnmodified() { return m_nTargetArea; }
        public int GetEffectLengthUnmodified() { return m_nEffectLength; }
        public int GetCooldownUnmodified() { return m_nCooldown; }

        // Mutators
        public void SetPowerModifier(int _power) { m_nPowerModifier = _power; }
        public void SetSpeedModifier(int _speed) { m_nSpeedModifier = _speed; }
        public void SetRangeModifier(int _range) { m_nRangeModifier = _range; }
        public void SetRecoveryModifier(int _recov) { m_nRangeModifier = _recov; }
        public void SetTargetAreaModifier(int _ta) { m_nTargetAreaModifier = _ta; }
        public void SetEffectLengthModifier(int _length) { m_nEffectLengthModifier = _length; }
        public void SetCooldownModifier(int _cd) { m_nCooldownModifier = _cd; }

        public void Save(BinaryWriter bw)
        {
            bw.Write((int)m_Type);
            bw.Write((int)m_Property);
            bw.Write((int)m_Effect);
            bw.Write(m_Name);
            bw.Write(m_ImageFilePath);
            bw.Write(m_nPower);
            bw.Write(m_nSpeed);
            bw.Write(m_nRange);
            bw.Write(m_nRecovery);
            bw.Write(m_nTargetArea);
            bw.Write(m_nEffectLength);
            bw.Write(m_nCooldown);
            bw.Write((int)m_MoveType);
        }

        public void Load(BinaryReader br, int version)
        {
            if (version == 0)
            {
                m_Type = (SpellType)br.ReadInt32();
                m_Property = (SpellProperty)br.ReadInt32();
                m_Effect = (SpellEffect)br.ReadInt32();
                m_Name = br.ReadString();
                m_ImageFilePath = br.ReadString();
                m_nPower = br.ReadInt32();
                m_nSpeed = br.ReadInt32();
                m_nRange = br.ReadInt32();
                m_nRecovery = br.ReadInt32();
                m_nTargetArea = br.ReadInt32();
                m_nEffectLength = br.ReadInt32();
                m_nCooldown = br.ReadInt32();
                m_MoveType = (SpellMoveType)br.ReadInt32();
            }
        }

        /// <summary>
        /// Creates the renderable spell object
        /// </summary>
        /// <param name="eventArgs">[0] string Spell Name to be cast</param>
        public void OnCreateSpell(params object[] eventArgs)
        {
            if ((string)eventArgs[0] != m_Name)
                return;
        }
    }
}
